<template>
  <div class="discoverMusic-radio">
    <div class="block text-center">
      <el-carousel :autoplay="false" height="300px">
        <el-carousel-item>
          <ul class="carousel-ul">
            <li v-for="item in classificationList" :key="item.id">
              <div
                class="carousel-ul-conter"
                :style="{
                  border: newId === item.id ? '2px solid red' : '',
                  borderRadius: newId === item.id ? '8%' : '0',
                }"
                @click="changeCategory(item.id)"
              >
                <div
                  class="carousel-ul-bimg"
                  :style="{
                    backgroundImage: `url(${item.picWebUrl})`,
                    backgroundPosition: newId === item.id ? '48px' : '0px',
                  }"
                ></div>
                <em
                  class="carousel-ul-title"
                  :style="{ color: newId === item.id ? 'red' : '' }"
                  >{{ item.name }}</em
                >
              </div>
            </li>
          </ul>
        </el-carousel-item>
        <el-carousel-item>
          <ul class="carousel-ul">
            <li>
              <div class="carousel-ul-conter">
                <div class="carousel-ul-bimg"></div>
                <em class="carousel-ul-title">情感</em>
              </div>
            </li>
            <li>
              <div class="carousel-ul-conter">
                <div class="carousel-ul-bimg"></div>
                <em class="carousel-ul-title">情感</em>
              </div>
            </li>
          </ul>
        </el-carousel-item>
      </el-carousel>
    </div>
    <div class="new">
      <div class="new-title">
        <h3>
          <span class="new-title-span">优秀新电台</span>
        </h3>
      </div>
      <ul class="new-content">
        <li v-for="item in classifiedRecommendationList" :key="item.id">
          <img v-lazy="item.picUrl" />
          <h3>{{ item.name }}</h3>
          <p>{{ item.rcmdtext }}</p>
        </li>
      </ul>
    </div>
    <div class="rdimore">
      <div class="rdimore-title">
        <h3>
          <span class="rdimore-title-span">电台排行榜</span>
        </h3>
        <div class="rdimore-title-content">
          <div class="rdimore-title-container">
            <span class="rdimore-title-rise">上升最快</span>
            <span class="rdimore-title-division">|</span>
            <span class="rdimore-title-hottest">最热电台</span>
          </div>
        </div>
      </div>
      <ul class="rdilist-content">
        <li v-for="item in hotSongList" :key="item.id">
          <img class="rdilist-content-img" v-lazy="item.picUrl" />
          <div class="rdilist-content-header">
            <h3>{{ item.name }}</h3>
            <div class="rdilist-content-header-introduce">
              <el-icon><User /></el-icon>
              <span>{{ item.dj.nickname }}</span>
            </div>
            <p class="">
              共{{ item.programCount }}期&nbsp;&nbsp;&nbsp;&nbsp;订阅{{
                item.subCount
              }}次
            </p>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script lang="ts">
export default {
  name: "XRadio",
};
</script>

<script lang="ts" setup>
import { User } from "@element-plus/icons-vue";
import { ElMessage } from "element-plus";
import type {
  AttClassificationList,
  AttrClassifiedRecommendationList,
  AttrGetHotSongList,
} from "@/api/discoverMusic/model/radio";
import {
  getClassificationList,
  getClassifiedRecommendationList,
  getHotSongList,
} from "@/api/discoverMusic/radio";
import { ref, onMounted } from "vue";

/************************************分类功能开始**********************************/
const classificationList = ref<AttClassificationList>([]);
onMounted(async () => {
  const res = await getClassificationList();
  const newRes = res.categories.map((item) => {
    return {
      id: item.id,
      name: item.name,
      picWebUrl: item.picWebUrl,
      picUWPUrl: item.picUWPUrl,
    };
  });
  ElMessage.success("页面更新成功");
  classificationList.value = newRes.splice(0, 18);
  //页面一加载默认渲染情感电台
  getClassifiedRecommendation(res.categories[0].id);
  getHotSong(res.categories[0].id);
});
/************************************分类功能结束**********************************/

/************************************根据id获取数据功能开始*************************************/
//定义一个id
const newId = ref<number>(3);
//定义分装切换分类数据
const classifiedRecommendationList = ref<AttrClassifiedRecommendationList>([]);
//封装切换分类请求函数
const getClassifiedRecommendation = async (id = 3) => {
  const res = await getClassifiedRecommendationList(id);
  // console.log(res);
  const newRes = res.djRadios.map((item) => {
    return {
      categoryId: item.categoryId,
      picUrl: item.picUrl,
      id: item.id,
      name: item.name,
      rcmdtext: item.rcmdtext,
    };
  });
  classifiedRecommendationList.value = newRes.splice(0, 5);
};
const changeCategory = (id: number) => {
  getClassifiedRecommendation(id);
  ElMessage.success("页面更新成功");
  getHotSong(id);
  newId.value = id;
};
/************************************根据id获取数据功能结束*************************************/

/*******************************************分类热门歌曲功能开始********************************************/
//定义热门歌曲数据
const hotSongList = ref<AttrGetHotSongList>();
//封装热门歌曲请求函数
const getHotSong = async (cateId = 3) => {
  const res = await getHotSongList(cateId);
  const newRes = res.djRadios.map((item) => {
    return {
      programCount: item.programCount,
      subCount: item.subCount,
      picUrl: item.picUrl,
      name: item.name,
      id: item.id,
      dj: item.dj,
    };
  });
  ElMessage.success("页面更新成功");
  hotSongList.value = newRes;
};
/*******************************************分类热门歌曲功能结束********************************************/
</script>

<style scoped>
/* 轮播图样式开始 */
.demonstration {
  color: var(--el-text-color-secondary);
}
.el-carousel__item ul {
  margin: 0;
}
.el-carousel__item:nth-child(2n) {
  background-color: white;
}
.el-carousel__item:nth-child(2n + 1) {
  background-color: white;
}

.carousel-ul {
  display: block;
  width: 100%;
  height: 200px;
  list-style: none;
  margin: 0;
  padding: 35px;
  text-align: center;
}
.carousel-ul li {
  margin: 35px 0 0 35px;
  list-style: none;
  display: block;
  float: left;
  margin: 0 0 25px 33px;
  /* width: 70px;
  height: 70px; */
}
.carousel-ul-conter {
  width: 70px;
  height: 70px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
}
.carousel-ul-title {
  top: 100%;
  font-size: 12px;
  color: #999;
}
.carousel-ul-bimg {
  display: inline-block;
  margin: 0 auto;
  width: 48px;
  height: 48px;
  /* background-image: url("./images/10001.jpg"); */
}
.carousel-ul-bimg-img {
  display: block;
  width: 96px;
  height: 96px;
}

/* 轮播图样式结束*/

/* 优秀新电台样式开始 */
.discoverMusic-radio {
  margin: 0 auto;
  padding: 0 40px;
  width: 1080px;
}
.new-title {
  display: flex;
  justify-content: space-between;
  height: 40px;
  border-bottom: 2px solid #c20c0c;
}
.new-content {
  list-style: none;
  margin: 0 0 50px 0;
  padding: 0;
  display: flex;
  justify-content: space-between;
}
.new-title-span {
  font-size: 24px;
  font-weight: normal;
}
.new-content img {
  margin: 10px 0;
  display: block;
  width: 150px;
  height: 150px;
}
.new-content h3 {
  margin: 13px 0 6px;
  line-height: 16px;
  font-size: 14px;
  font-weight: normal;
}
.new-content p {
  line-height: 18px;
  color: #999;
  font-size: 12px;
}
/* 优秀新电台样式开始 */

.rdimore-title {
  display: flex;
  justify-content: space-between;
  height: 40px;
  border-bottom: 2px solid #c20c0c;
}
.rdimore-title-span {
  font-size: 24px;
  font-weight: normal;
}
.rdimore-title-content {
  display: flex;
  align-items: flex-end;
}
.rdimore-title-container {
  margin-bottom: 10px;
}
.rdimore-title-rise {
  color: #c20c0c;
  font-size: 12px;
}
.rdimore-title-division {
  margin: 0 10px;
  color: #c7c7c7;
}
.rdimore-title-hottest {
  color: #666;
  font-size: 12px;
}

.rdilist-content {
  display: flex;
  flex-wrap: wrap;
}
.rdilist-content-img {
  margin: 20px 0;
  width: 120px;
  height: 120px;
}
.rdilist-content li {
  margin-right: 30px;
  width: 470px;
  display: flex;
  border-bottom: 1px solid #999;
}
.rdilist-content-header {
  margin: 20px;
}
.rdilist-content-header h3 {
  height: 64px;
  margin: 0;
  line-height: 64px;
}
.rdilist-content-header-introduce span {
  margin-left: 5px;
  font-size: 12px;
}
.rdilist-content-header p {
  color: #999;
  font-size: 12px;
}
</style>
